Xml streaming transformer (xst)

ABSTRACT

The present invention includes devices and methods to specify a document transformation. A template specifies a transformation that is applied to a document in a streaming mode, without building a full object tree in memory representing the document.

RELATED APPPLICATIONS

This application is a continuation of U.S. application Ser. No.14/313,815, filed 24 Jun. 2014, entitled XML STREAMING TRANSFORMER(XST)”, which is a continuation of U.S. application Ser. No. 12/759,585,filed on 13 Apr. 2010, entitled “XML STREAMING TRANSFORMER (XST)”, whichis a continuation of U.S. application Ser. No. 10/222,752, filed on 16Aug. 2002, entitled “XML STREAMING TRANSFORMER (XST)”.

COPYRIGHT NOTICE

A portion of the disclosure of this patent document contains materialthat is subject to copyright protection. The copyright owner has noobjection to the facsimile reproduction by anyone of the patent documentor the patent disclosure as it appears in the Patent and TrademarkOffice patent file or records, but otherwise reserves all copyrightrights whatsoever.

BACKGROUND OF THE INVENTION

The present invention relates to systems and methods for fixed andextremely low memory usage transformation of a document treated as astream of discrete processing events instead of requiring representationof hierarchical relationships between all elements to be constructed andnecessitating traversal of this hierarchical object representation ofthe document in order to accomplish transformation. More particularly,it relates to systems and protocols for transforming XML documents.

Business-to-business (B2B) and application-to-application (A2A)electronic commerce are replacing former protocols for electronic datainterchange (EDI). As businesses strive to improve their efficiency withB2B and A2A systems, a number of incompatible platforms and competingstandards have emerged. One need that has been identified is totransform XML documents, typically converting the documents from onesystem to another. Another reason for transformation is that a standardmay have gone through several versions and one end may use the olderversion the other the newer.

XML has become a widely used type of data because the rigid rules thatmust be applied to create inline markup make it relatively simple forcomputer programs to interpret and process the content of textualdocuments. For example, a purchase order written in XML can be processedby an order entry software application that knows how to read the markupannotations that describe what is being purchased, who the purchaser is,and so forth. Thus, a third reason for a transformation would be to takethe information in the purchase order and to use it to produce aresponse document such as a Shipping Bill containing the purchaser, theitems being purchased and other information copied from the firstdocument.

Transformation is a major category of computer processing. A paperlesssystem for transacting business could, in a large-scale marketplace,require the transformation of many thousands of XML documents a day. TheXML documents are often quite large in size, with many thousands ofindividual data elements which must be handled in the transformation.The rules expressing the conversion from input to output may also bevery extensive. The response time necessary to complete an individualtransformation may be excessively long and the overall demand oncomputer resources for supporting an enterprise-scale transformationservice may grow rapidly to unacceptable proportions.

While there are many different tools which accomplish XMLtransformation, there is a lack of tools effectively designed to addressthe issue of performance. The most popular technology used today, XSLT,exacerbates the performance problem by requiring an internal data modelthat typically is extremely costly in computer resources. Some attemptshave been made to alleviate these problems by compiling XSLT conversionstatements into a more efficient programming language such as Java or bycaching schemes. These approaches do not alter the basic process that iscausing the inefficiency.

Accordingly, an opportunity arises to devise methods and structures thatefficiently specify and implement XML document transformations.

SUMMARY OF THE INVENTION

The present invention relates to systems and methods for fixed andextremely low memory usage transformation of a document treated as astream of discrete processing events instead of requiring representationof hierarchical relationships between all elements to be constructed andnecessitating traversal of this hierarchical object representation ofthe document in order to accomplish transformation. Particular aspectsof the present invention are described in the claims, specification anddrawings.

BRIEF DESCRIPTION OF THE DRAWINGS

FIG. 1 is a high-level block diagram of a transformation process. FIG. 2is also a high-level block diagram, depicting separate processing ofinput-events and end-events.

FIG. 3 is a high-level block diagram of an XST transformation engine.

FIGS. 4 through 6 provide additional detail of elements that appear inFIG. 3.

FIGS. 7 through 9 are flowcharts, in one embodiment, for processingevents in an event stream.

FIG. 10 is a flowchart for processing lookups against a schema adjunctframework, which may be used in one embodiment.

FIGS. 11 and 12 depict alternative implementations, utilizing differentSAX parsers.

FIG. 13 is a high-level block diagram of template processing.

FIG. 14 is a high-level block diagram of XML instance processing,following template processing.

FIGS. 15A-C illustrate a schema for an embodiment of XST.

DETAILED DESCRIPTION

The following detailed description is made with reference to thefigures. Preferred embodiments are described to illustrate the presentinvention, not to limit its scope, which is defined by the claims. Thoseof ordinary skill in the art will recognize a variety of equivalentvariations on the description that follows.

XST is a transformation technology. Transformation is the mutation of aninput source into an output using a set of a deterministic set of rulesthat describe the mutation. In one embodiment, XST operates on sourcedata marked up in XML or a similar structured and tagged markuplanguage. XML data is annotated by inline markup conforming to syntaxrules of XML. The output of an XST transformation is textual data, whichalso may be an XML document.

An XST transformation is described by a set of rules contained in atemplate. These rules are expressed in a language. Transformationlanguages resemble general-purpose programming languages but provideonly the expressiveness needed to describe the mutations needed tomutate from legal inputs to legal outputs. When the legal inputs arelimited to XML or similar structured and tagged documents, the problemspace is quite limited compared to general transformation.Transformations are therefore easier for programmers to write and theimplementation of a processor to compute transformation described intemplates is an easier task. Templates define the significant inputevents in sequential processing of the source document wheretransformation operations occur. In one embodiment, the input eventdefinition and associated transformation operations can be calledsubtemplates. It is at the subtemplate level that streaming to outputtakes place. Numerous examples follow.

Even with the limited scope of XML transformation, it is possible todevise many different approaches to transformation languages. The mostcommon type of language, of which XSLT is a good representative, is onewhere the XML input document is manipulated as a tree of nodes. For XMLdocuments, this provides a way to describe transformations that isgenerally thought to be intuitive and to provide wide expressivenessthat allows the transformation programmer to express almost anytransformation process with relative ease. The problem with this type oflanguage is that it forces the underlying implementation to actuallyconvert an entire XML document into a tree of nodes and to perform themanipulations required by the transformation as tree-based nodeoperations. The conversion of the XML document to a tree is a costlyoperation and subsequent operations on the tree may also be very costly,especially if a great deal of backtracking between nodes is required.Typically, the entire XML document is converted to a tree in memory andthis tree occupies several times the size of the document compared toits representation as a byte stream. Various optimizations to reduce theamount of memory needed to store the tree are, of course, possible, butthey are prohibitively difficult to implement. And these optimizationsmay require tradeoffs of slower performance for better memory usage. Forthese and other reasons, the underlying implementations of thetree-oriented type of transformation language are not optimized in thearea of tree representation or tree size.

The XST transformation language is deliberately restricted to enable amore efficient underlying implementation of the transformation process.In studying hundreds of existing transformations, the observation wasmade that the majority of them do not require the expressiveness of afully tree-based language. XST uses a simpler paradigm for its basic,default processing and uses more complex and costly constructs onlywhere they are required, for specific fragments of an XML document. TheXST approach also accepts that for certain classes of transformations,templates may be difficult to write and performance may be no betterthan with tree-based languages. Accordingly, XST can providehigh-performance for the large class of transformations that can bereadily expressed in a more limited idiom.

In order to process an XML input stream, the stream is scanned in orderto recognize inline markup and the content annotated by the inlinemarkup. The recognition of markup and content produces so-called“events” and the process is sometimes called “event-stream parsing”. Anadditional, more complex process is required to form a tree of nodescapturing the hierarchical relationships between content items fromthese events. In constrained circumstances, XST can process an eventstream forming a tree of nodes, even in a single pass through an XMLdocument. Single pass, non-tree processing may use relatively smallbuffers, enabling memory usage to be kept very small. Processing timemay, despite the small buffers, be faster because time is not spent toconstruct the tree or to make multiple passes over the tree to process atransformation.

Application of event-stream parsing to XML document transformation isinnovative. The XST language is carefully designed to allow the bulk oftransformation processing to be implemented using the efficientevent-stream parsing method. Several aspects of XST extend event-streamparsing to a large class of transformation problems. Mutable variablescan be used in event-stream processing to forward-reference informationfrom prior events and to compute context-specific values. Portions ofthe output stream can be divided and directed to multiple outputtargets. Java methods and other external processing routines can beinvoked from events. In some embodiments, XST allows for the possibilityof mixing tree-based node processing into an event-stream process byallowing trees to be constructed on fragments or subsections of adocument. XST also allows additional event handlers to be chainedtogether before and after the main XST transformation event handler.

FIG. 1 is a high-level block diagram of event processing. The eventprocessing depicted here operates on named template elements,transforming an electronic commerce document, preferably one representedin XML, but more generally including documents comprising character dataencoding text characters and markup data identifying sets of storageunits according to a logical structure of any document. Many options areillustrated or described below that can be utilized in variouscombinations. A parser generates an event stream 101 corresponding tothe electronic commerce source, which may be a file or any blob orstream of data. Software hosted on a computer system is adapted toreceive events 102 generated by the parser corresponding to theelectronic document source. In some embodiments, the events includeelement start-events 103, input events and element end-events 105. Inother embodiments, the parser may pass tokens and the system may beadapted to generate events from the tokens. In yet other embodiments, acharacter stream may be received and parsed to generate tokens orevents. Responding to an element start-event 103, a computer-assistedsystem matches an element to a named template 104. This may beaccomplished by matching an element name, passed as part of the elementstart-event, with the corresponding name of an element template. Aplurality of template instances, as illustrated in other figures, may bestored in a tree in memory. Alternatively, the template instances may bestored in another data structure, for instance one accessible by asimple API for XML (SAX). In some embodiments, a plurality of templateinstances are stored together in a templates source. Lacking a match,the element represented by the start-event is treated as content of itsparent element. An XST transformation should include a template elementthat matches a root element of an electronic commerce document. Soconstrained, a child element that lacks a matching template can betreated as content of its parent element. Content of an element mayinclude all of what appears between the token(s) that trigger an elementstart-event and the token(s) that trigger an element end-event. Contentmay or may not include nested sub elements. Content, may or may notinclude attributes of an element, for instance, attributes of anXML-formed element. In the case of a match between an elementrepresented by an element start-event and a named template orsubtemplate from the templates source, the system activates the namedtemplate. When processing reaches an element end-event 105, the systemattempts to match the element with a corresponding activated namedtemplate. This attempt fails if the corresponding element start-eventdid not match a named element. In the case of a match with thecorresponding activated named template, processing is performed 106.Processing may include output of both literal text from the template andinput events from the stream. Responsive to instructions in theactivated named template, the system outputs literal text or contentfrom input events corresponding to the current element. Having processedthe content of the current element, the system can clear the inputevents, for instance, from an input buffer. The activated named templatecan be deactivated.

This embodiment may be enhanced by use of mutable variables with thetemplates. The variables can be activated for the processing of adocument or may be limited in scope to processing of a named template(including any nested named templates.) Response to an elementstart-event may include activating one or more variables; response to acorresponding end-event may include deactivating the variables. Inputstream values may be assigned to mutable variables or to un-named,non-mutable variables. Mutable variables may be changed using substring,concatenation or other operators. Processing an end-event andcorresponding template may include manipulating the variables. Variablesmay be manipulated by external processing routines, such as Javamethods.

This embodiment further may be enhanced by use of flow of controloperators in a template. The flow of control operators may be as simpleas “if” and “choose”. They may further include “for-each,” “when,” and“otherwise” operators. Constructs such as “else” and “then-else” alsomay be used. Some flow of control operators operate on a fragment orsubsection of the input document that is converted into a treestructure.

FIG. 2 is an alternate high-level block diagram of event processing.This event processing also operates on named template elements. An eventstream 101 is generated by a parser separate from the system or by acomponent of the system. The processing module receives 102 the eventstream. It matches 104 element start-events 103 as described above. Inresponse to a match, the system may set up one or more variables tostore content, attributes, or labels corresponding to an element.Depending on the structure of the template elements, the variables havea local or global scope. When the variables have local scope, they areactive as long as the corresponding named template is active. When thevariables have global scope, they are active throughout transformationof the document. The system generally processes end-events 105 by theoutput process 106 described above. In addition to processing (104, 212,106) literal text from the template and input events 211 from thestream, processing also may include manipulating the variables,including assigning parts of the input stream to the variables andperforming logical, string, arithmetic or other operations on thevariables. The content of the variables, either manipulated or not, maybe output. Processing may further include flow of control instructions,as described above, and invocation of external processes. The externalprocesses may include Java classes and methods, as further describedbelow.

In a first embodiment, the XST template language supports the followingthree processing commands: <xst:template> is an opening tag of an XSTtemplate and is used to store more than one template in one file.<xst:pi> is an opening tag of XST processing instructions. <xst:var> isan opening tag of an XST variable.

In an alternative embodiment, processing commands are treated asattributes of a template and a “templates” markup is provided as aparent to multiple instances of a “template” markup.

An XST template is a text file that includes string literals andtemplate variables. Variables have the form<xst:var>variableName</xst:var> with an opening tag of “<xst:var>” and aclosing tag of “</xst:var>”. The variables provide the bindings betweenthe template and its corresponding source XML document.

A transformation begins with the parsing of an XML document. As XMLdocuments have a root element, XST transformations have a root template.If the name of the element is root, then the template may be namedroot.tpl, combining of the name of the root element and the extension,“.tpl”, where root is some arbitrary element name. A child template maybe attached to a parent template through its parent element in the XMLdocument.

In alternative embodiments, the XST transformation engine can operate ineither streaming or buffered mode. The intermediate output of atransformation, like the template, includes string literals and templatevariables. In streaming mode, the transferred output of each template isstreamed out upon deactivating or unloading of the template. In bufferedmode, the results of the transformation are output and intermediatestorage is flushed out at the end of the transformation or untildeactivation of a parent template. The order of elements in the outputcan be different from that of the input document, within each template.

By design, the XST transformation reuses loaded templates. In oneimplementation, a list of loaded templates for an XML document is savedunder the name of the root template of that document. All the lists aresaved in memory for fast access. To minimize the usage of memory theengine writes out the transformed results to the target output stream,as practical.

An XST transformation corresponding to an XML document includes one ormore templates corresponding to elements of the XML document. Multipletemplates can be stored in a single file. A simple string comparison ofthe name of an element in an XML document and that of a templatedetermines if a matching template exists that should be activated orloaded during a transformation. Template names may be qualified by anamespace name.

The XST transformation engine provides public interfaces to transform anXML document using either a default XML parser/reader or a user selectedone. It also supports a Java API for XML parsing (JAXP) interface. Theengine runs as either a stand alone service or a part of other services.

A first embodiment of the XST transformation engine 302 includestemplate transformer 303, source document handler 305 and templateprocessor 306 modules, as shown in FIG. 3. The template transformer 303provides the public interface to transform an XML document using XST.The source document handler 305 is registered as the content handler toreceive various SAX events from an XML reader/parser 301 and pass themto the template processor 305. The template processor 306 handles theSAX events from the XML parser 301. It also provides the mechanism tocache/reuse a loaded template and lookup the value of an element usingthe rules specified in the Schema Adjunct Framework (SAF) 307.

As shown in FIG. 4, the template transformer 402 provides the followingpublic interfaces 401, 403 to (1) transform an XML document using eithera default XML reader/parser or a user selected one; (2) get the contenthandler which can be used with other XML transformers/adapters to handlethe SAX events; (3) set the output stream; and (4) get the outputdocument of a transformation.

As shown in FIG. 5, the document handler 502 provides the publicinterfaces 502 to (1) get the output document; (2) set the output targetstream; (3) get a list of the currently used templates on the stack; and(4) put a list of templates on the stack to use. It also providesinterfaces of SAX event handlers 501 which simply pass the events to itstemplate processor.

In addition to set/get interfaces provided by the document handler 502,the template processor 602 also provides a method getProperty( ) 603 tolook up a property using SAF 307, as shown in FIG. 6. Five interfaces ofthe SAX event handler 601 have been provided for the XST transformation603. Handler startDocument( ) calls the method reset( ) to reset thestates of some of the instance variables of the template processor.Handler endDocument is reserved. The process flows for startElement,characters or input, and endElement events generated by a SAX processorand handled by SAX event handlers are shown in FIGS. 7-9, respectively.

FIG. 7 depicts the flow within a startElement module. In thisembodiment, the startElement module is invoked with parameters that mayrepresent an abstract data type, such as data types compliant withDocument Type Definition (DTD), XML-Data Reduced (XDR), Document ContentDescription (DCD) for XML, Schema for Object-oriented XML (SOX),Document Definition Markup Language (DDML), XML Schema, Regular LanguageDescription for XML (RELAX/Core/NG), Tree Regular Expressions for XML(TREX), or Schematron. At step 702, the input is tested to determinewhether to load a schema and template. Step 705 includes getting theschema and template. For a particular abstract data type, an abstracttree is created and can be queried. The logical branch at step 706depends on whether a root template has been initialized. If so, thetemplate being opened is attached to its parent template at step 708. Ifnot, the template being opened is the root template, and a flag is setin step 707. In step 709, the newly activated template is pushed onto atemplate stack. In step 710, which may be reached from 709 or 703,attributes of an element are processed. When the element is encodedusing XML, the attributes are XML attributes. Upon completion ofattribute processing, the routine returns. Again at step 702, if theelement being processed does not correspond to a named template, thenext decision fork 703 determines whether the most recently activatedtemplate is set to copy the contents of the corresponding element. Atthis point, a sub-element is treated as content of its parent element.If copy is set, processing proceeds to 704, which sets up copying and to711 which copies attributes passed when the startElement method isinvoked, before returning at step 712. If the template is not set tocopy the contents, then the input stream corresponding to the currentelement is not copied to output. From 703 to 712, the method returns.

FIG. 8 depicts the flow within a module processing an input stream 801.In this embodiment, the first logical branch 802 uses the method lookup() to determine whether a schema adjunct framework applies to processingthis input stream. There must both be an applicable schema adjunctframework and it must be accessible (< > null). If a schema adjunctframework is applicable and available, it is applied 803. The nextprocessing branch determines whether a variable exists with the samename as the current element. If a variable exists for the currentelement, a set variable method may be called 806 to transfer all or partof the input stream to the variable, before returning 808. If novariable exists for the current element, the logical branch 805determines whether a copy instruction or attribute has been invoked. Ifso, a copy( ) method 807 is invoked. If not, or after copying, themethod returns 808. With minor modification, the processing of atemporarily buffered input events stream can be postponed until anelement end-event.

FIG. 9 depicts the flow within a module processing an end-element event901. The first logical branch 902 matches the currently active templateto the element that is ending. This may be done by matching a namepassed as a parameter to the method with part of the current template'sname. In the flow chart, the approach depicted is to concatenate theextension “.TPL” to the name of the element and to match that againstthe current template, though any chosen extension may be used. Inembodiments that process input events on an ongoing basis, the lack of amatch leads to a method return 906. In embodiments that postponeprocessing temporarily buffered input events until an element end-event,some processing may be performed, for instance copying of partialcontents of an element, even if there is no match for the elementend-event. In case of a match, in embodiments that store templates on astack, the current template is popped off the stack for processing 903.The next logical branch 904 determines whether a copying instruction orattribute is effective. If so, a buffer can be output and flushed 905.Processing then continues in either case 904 or 905, with the methodreturn 906.

FIG. 10 is a block diagram for the process flow, in the first embodimentof XST using a schema adjunct framework. A general framework SchemaAdjunct Framework has been integrated into this embodiment of XST toallow users to specify additional information about the structures orproperties of an XML document to be transformed. A Schema Adjunct is anXML document that contains additional, application-specific ordomain-specific data relative to a particular schema. Additionalinformation regarding SAF technology appears in Vorthmann, S. et al.,“The Schema Adjunct Framework,” accessible on Aug. 31, 2009 athttp://web.archive.org/web/20010219205703/www.extensibility.com/tibco/resources/saf_dec2000.htm.

A template processor 1001 handles certain events in the event stream,generally corresponding to the lookup( ) method 803 in FIG. 8. For aparticular element, the logical branch 1002 determines whether an SAFlookup is required. If not, the method returns 1008. If so, the nextlogical branch 1003 determines whether the required SAF is accessible.If not, the method returns 1008. In one embodiment, the schema adjunctframework invokes a Java application. The template processor gets theclass name and method name 1004 and then gets a class instance and classmethod 1005. If the class method is not null 1006, it is invoked 1007.Invoking the class method may involve invoking a service external toXST. After the class method has been invoked and returns, the templateprocessor returns 1008.

The following example illustrates use of SAF to provide the current dateand time to the content of the element <RefDate> of an XML document. AJava class is used for this extension.

<schema-adjunct target=“...”>  <document>  <param-list>BuyerChangeOrderNumber ;  ChangeOrderIssueDate;RefNumber</param-list>  </document>  ...... <element which = “RefDate ”>  <class>test.xst.templates.InfoRetriever</class>  <method>getDateTime</method>  </element>  ......  </schema-adjunct>

In this above example, the content of the element <param-list> specifiesa list of leaf elements to be saved in a hashtable object by XST;RefDate corresponds to the name of an element in the source XMLdocument; test.xst.templates.InfoRetriever is the name of the Java classto provide the Schema Adjunct extension; and getDateTime is the name ofthe method of this class to be called. The <param-list> enables the SAextension to access the elements that have been processed by XST, fromthe source XML document.

Sample code for the Java class, used to provide the updated informationfor the element <RefDate>, is shown below.

/* * File Name: InfoRetriever.java */ package test.templates; importjava.util.Hashtable; import java.util.Date; import java.util.Properties;import com.commerceone.xst.utils.PropertyReader; public classInfoRetriever {  private Properties props;  public InfoRetriever( )  {  this.props = PropertyReader.getProperties(PROP_FILE);  }  ...... public String getDateTime(String localName, String value, Hashtable ht,String event)  {  return (new Date( )).toString( );  }  static privateint cnt = 0;  static private String PROP_FILE =“test/templates/DefaultInfo.prop”; }

The method providing the SAF extension may have four arguments, as shownin the above sample code, where localName and value are corresponding tothe name and value of an element, under transformation, in the originalXML document; ht is the hashtable to store a list of leaf elementsspecified by the content of the element <param-list> in the SAFdocument; and event is the name of a SAX event when the method isinvoked. It is noted that the arguments passed to this method are notused in the sample code. When lookup is enabled, the above method willbe invoked by the XST to provide additional information to the element<RefDate> under transformation.

The following example shows a sample source document, ChangeOrder.xml,with the element <RefDate> in it.

<?soxtype urn:x-commerceone:document:com:commerceone:XCBL35:XCBL35.sox$1.0?><ChangeOrder>  <ChangeOrderHeader>   <ChangeOrderNumber>   <BuyerChangeOrderNumber>4500006637</    BuyerChangeOrderNumber>  </ChangeOrderNumber>   <ChangeOrderSequence/><ChangeOrderIssueDate>20010521T12:00:00</ChangeOrderIssueDate>  <OrderReference>    <Reference>     <RefNum>4500006637</RefNum>    <RefDate>20010521T15:27:17</RefDate>    </Reference>  </OrderReference>   <SellerParty>   ......  </ChangeOrderHeader> ...... </ChangeOrder>With most of the logic in the SAF extension processing, a simpletemplate is used to transform the ChangeOrder element:

<xst:templates> <xst:pi>NAME=ChangeOrder.tpl;COPY=true</xst:pi></xst:template>

Using this template with the SAF document and the Java class shownabove, and running XST on Sep. 21, 2001 at 15:27:17, the transformeddocument below results:

<?soxtype urn:x-commerceone:document:com:commerceone:XCBL35:XCBL35.sox$1.0?><ChangeOrder> <ChangeOrderHeader>  <ChangeOrderNumber><BuyerChangeOrderNumber>4500006637</BuyerChangeOrderNum- ber>|</ChangeOrderNumber> <ChangeOrderSequence/><ChangeOrderIssueDate>20010521T12:00:00</ChangeOrderIssueDate><OrderReference>  <Reference> <RefNum>4500006637</RefNum><RefDate>20010921T15:27:17</RefDate>  </Reference> </OrderReference><SellerParty>  ......  </ChangeOrderHeader> ...... </ChangeOrder>

In this transformed document, the element <RefDate> has an updateddate/time, provided by the Java SA extension.

The following example illustrates how to use SAF to provide additionalinformation to a field “address1” of an XML document. A Java class isused for this extension.

<schema-adjunct target=“po.dtd”>   ......  <element which = “address1”><class>test.xst.templates.AddressRetriever</class><method>getAdditionalAddressInfo</method> <mode>replace</mode> </element>   ...... </schema-adjunct>where “address1” is the field in the original XML document to betransformed/modified; “test.xst.templates.AddressRetriever” is the nameof the Java class; “getAdditionalAddressInfo” is that of the method ofthis class to be called, and “replace” is the mode of the operation onthe returned value. The sample code for the Java class used is shownbelow.

package test.xst.templates; public class AddressRetriever {  publicAddressRetriever( ) { }  public String getNewAddressInfo(StringlocalName, String value, Hashtable params)  {  return “ The new addressis: “ + localName + ”=” + value;  }  public StringgetAdditionalAddressInfo(String localName, String value, Hashtableparams)  {  return “ !! Additional address info for “ + localName + ”.The original value is:“ + value + ”.”;  } }The signature of the method may have three arguments, “StringlocalName”, “String value” and “Hashtable params”.where “localName” and“value” are corresponding to the name and value of a field undertransformation in the original XML document; and “Hashtable params” isthe “hashtable” to store a list of names specified in the schema adjunctdocument and their available values in the XML document. When lookup isenabled, the above method will be invoked by the XST to provideadditional information to an XML document under transformation.

The XST transformation engine provides interfaces to transform an XMLdocument using a default XML parser, such as Xerces, or a user selectedparser. The in FIGS. 11 and 12, two alternative parsers are used togenerate event streams. The particular parsers illustrated in thisenvironment are XML parsers. The parsers are a default Commerce One XMLparser 1101 and an Xerces/Xalan parser 1201. Sample syntax and semanticsfor invoking these parsers is illustrated. In either case, the output ofthe parser is input to an XST transformation engine 1102. The XSTtransformation engine comprises a template transformer 1103, a sourcedocument handler 1104, and a template processor 1105. More detail ofinteraction among these components is illustrated in FIGS. 13 and 14,for a template source and a document source.

In the second embodiment, the high level design supports additionalfeatures. XST templates with similar syntax to that of XSLT stylesheetare used. All templates used for a transformation reside in one templatesource, or are included by reference in the template source. Additionaltemplates can be added through a public interface or API. Fragments orsubsections of the source document may be represented by a treestructure that is accessible using of XPath expressions or treemanipulations. The logical operations if, choose, when and otherwise aresupported in XST templates. Built-in functions are provided for string,substring, concatenation functionality. A Java extension functionhandler can be installed to handle user-defined extension functions. Thehandler supports calling a Java method by specifying both its class pathand method name. Variables that accept values from the input stream aremutable during the transformation. In alternative embodiments, featuresof the first and second embodiments can be mixed and matched.

The high-level architecture of the second embodiment resembles thefirst, as depicted in FIGS. 13-14. FIG. 13 is a diagram showing theprocess flow to parse the XST template source. FIG. 14 is a diagramshowing the process flow to transform an XML instance. In the figures,the transformer module 1303 provides a convenient way to use XST with anXML parser 1304 such as the Commerce One's CXPParser or Xerces parser.It also provides the interfaces to get a new instance of the contenthandler and a list of templates used. The handler module 1305 providesthe content handlers for both the template and source document 1301.Those handlers can be used with any XML parsers, preferably parsers thatcomply with the W3C standards. The handlers send the SAX parsing eventsto XST processor 1306 for further processing. The processor module 1306provides the template processor to process the XST templates 1301 into atree of DOM elements 1407 and the source document processor to transformthe XML instance 1401 using a list of template elements 1408. An XSTtemplate 1401 is a valid XML document that provides the rules for atransformation. The template module includes the classes for each of theelements in a template. It also provides the mechanism to stream andclone a template. The module Xpath, not shown in the figures, providesthe adapter classes to use and execute XPath expressions implemented byan XPath engine.

Returning to the first embodiment, the public interface to the documenthandler 1305 provides several method calls. The getOutputDocument methodmay be declared as: public XSTtemplate getOutputDocument( ). This methodreturns the current root template used in a transformation. ThegetOutputStream method may be declared as: public java.io.OutputStreamgetOutputStream( ). This method returns the target output stream used inthis transformation. The getContentHandler method may be declared as:public org.xml.sax.ContentHandler getContentHandler( ). This methodreturns the ContentHandler of this handler. The getTemplates method maybe declared as: public java.util.Hashtable getTemplates( ). This methodgets the current template list. The putTemplates method may be declaredas: public void putTemplates(java.util.Hashtable templList). This methodputs a list of template to the current or active template list. ThesetOutputStream method may be declared as: public voidsetOutputStream(java.io.OutputStream os). This method sets the outputstream for this transformation. The setSiblingContentHandler method maybe declared as: public voidsetSiblingContentHandler(org.xml.sax.ContentHandler handler). Thismethod puts a sibling handler at the end of the sibling list.

The public interface for DocumentProcessor extends theTemplateProcessor. It also includes several methods. It inherits from aSAX compliant template processor methods including characters, comment,endDocument, endElement, processingInstruction, pushElement,pushTemplate, startDocument, startElement. In addition, thegetOutputStream method of the DocumentProcessor interface may bedeclared as: public java.io.OutputStream getOutputStream( ). This methodgets the output stream used by this processor. This object cannot benull for a streaming mode transformation. The getDOMByRootName methodmay be declared as: public org.w3c.dom.NodegetDOMByRootName(java.lang.String name). This method retrieves the DOMobject for a given name. The getOutputTemplate method may be declaredas: public XSTtemplate getOutputTemplate( ). This method gets the outputtemplate which is the root template of this transformation. ThegetSchemaPath method may be declared as: public java.lang.StringgetSchemaPath( ). This method gets the schema path for the SchemaAdjunct document. The getTemplatePath method may be declared as: publicjava.lang.String getTemplatePath( ). This method gets the template path.The getTemplates method may be declared as: public java.util.HashtablegetTemplates( ) This method gets the current template list. ThegetXPathContext method may be declared as: publicorg.apache.xpath.XPathContext getXPathContext( ). This method gets theXPath running context, which should include the context node in thesource document tree. The lookup method may be declared as: publicjava.lang.String lookup(java.lang.String key, java.lang.String value,java.util.Hashtable ht, java.lang.String method, java.lang.String event,XSTtemplate templ). This method looks up the value for a given nodeusing a specified method. In its parameter list: localName is the nameof the context node which is also the name of the first choice; value isthe value of the context node; ht is a Hashtable used to store valuesfor the params specified in a template; method is the name of the methodused for the lookup; event is a SAX event when this method is called;and templ is the template of the context node. This method returns avalue for the given context node. The putTemplates method may bedeclared as: public void putTemplates(java.util.Hashtable templList).This method adds a list of templates to the current template list. ThesetOutputStream method may be declared as: public voidsetOutputStream(java.io.OutputStream os). This method sets theOutputStream for this processor, for a streaming mode transformation.The setSchemaPath method may be declared as: public voidsetSchemaPath(java.lang.String path). This method sets the schema pathfor a Schema Adjunct document. The setTemplatePath method may bedeclared as: public void setTemplatePath(java.lang.String path). Thismethod sets the template path.

The public interface for TemplateProcessor includes several methods. ThegetTemplates method may be declared as: public java.util.HashtablegetTemplates( ) This method gets the current template list. ThepushElement method may be declared as: public voidpushElement(java.lang.Object elem). This method pushes the element tothe element stack. The pushTemplate method may be declared as: publicvoid pushTemplate(java.lang.String name, java.lang.Object templ). Thismethod pushes the template to the template stack, when name is the nameof the object to be pushed and templ is the object of the template to bepushed. The characters method may be declared as: public voidcharacters(char[ ] ch, int start, int length) throwsorg.xml.sax.SAXException. This is the SAX event handler interface forcharacters or input. In its parameter list: ch is a character arraycontaining the value of the current element; start is an index of thefirst character in the character array for the value of the currentelement; and length is the number of characters for the value of thecurrent element. The endDocument method may be declared as: public voidendDocument( ) throws org.xml.sax.SAXException. This is the SAX eventhandler interface for endDocument. The endElement method may be declaredas: public void endElement(java.lang.String namespace, java.lang.StringlocalName, java.lang.String rawName), throws org.xml.sax.SAXException.This is the SAX event handler interface for endElement. In its parameterlist: localName is the node name of the current element without prefix;and rawName is the qualified name of the current element (with prefix).

The startDocument method may be declared as: public void startDocument() throws org.xml.sax.SAXException. This is the SAX event handlerinterface for startDocument. The startElement method may be declared as:public void startElement(java.lang.String namespace, java.lang.StringlocalName, java.lang.String rawName, org.xml.sax.Attributes atts) throwsorg.xml.sax.SAXException, javax.xml.transform.TransformerException,java.io.IOException. SAX event handler interface: startElement. In itsparameter list: namespace is the namespace of the current element;localName is the local part of the qualified name of the current element(without prefix); rawName is the qualified name of the current element(with prefix); and attributes is a list of the attributes associatedwith the current element. The processingInstruction method may bedeclared as: public void processingInstruction(java.lang.String target,java.lang.String data) throws org.xml.sax.SAXException. This is the SAXevent handler interface for processingInstruction. In its parameterlist: target is the processing instruction target; and data is theprocessing instruction data, or null if none is supplied. The methodthrows an org.xml.sax.SAXException, which any can be SAX exception,possibly wrapping another exception. Comments are supported.

The public interface XSTElement supports elements of the XSTtransformation language. The details of this interface vary between thefirst and second embodiments. The first embodiment includes severalmethods. The appendChild method may be declared as: public voidappendChild(XSTElement elem). This method appends a child element tothis element. The appendAndPushChild method may be declared as: publicvoid appendAndPushChild(XSTElement elem). This method appends a childelement to this element and push it to the element stack of itsprocessor. The appendContent method may be declared as: public voidappendContent(java.lang.String content). This method appends the contentof String to the content of this element. The appendContent method maybe declared as: public void appendContent(java.lang.Object content).This method appends the content of an Object to the content of thiselement. The attachChild method may be declared as: public voidattachChild(XSTElement elem). This method attaches a child element tothis element even though it may not be a direct child. The clone methodmay be declared as: public java.lang.Object clone( ). This method clonesthis element and returns a copy. The cloneAll method may be declared as:public XSTElement cloneAll( ). This method clones this element includingall of its children. The execute method may be declared as: publicjava.lang.Object execute( ). This is an entry point to the elementtransformation. It returns the result of the element transformation. Theexecute method may be declared as: public voidexecute(java.io.OutputStream os) throws java.io.IOException. This methodexecutes the transformation of this element and sends the result to theOutputStream. The getAttribute method may be declared as: publicjava.lang.String getAttribute(java.lang.String qname). This methodretrieves the content of an attribute for the given name. The getChildmethod may be declared as: public XSTElement getChild( ). This methodgets the first child of this element. The getContent method may bedeclared as: public java.lang.Object getContent( ). This method gets thecontent of this element. The getElementName method may be declared as:public java.lang.String getElementName( ). This method gets the nameattribute of this element. The getName method may be declared as: publicjava.lang.String getName( ). This method gets the name of this element.The getNamespace method may be declared as: public java.lang.StringgetNamespace( ). This method gets the namespace of this element. ThegetParent method may be declared as: public java.lang.Object getParent(). This method gets the parent element of this element. The getSiblingmethod may be declared as: public XSTElement getSibling( ). This methodgets a sibling element of this element. The setProcessor method may bedeclared as: public void setProcessor(TemplateProcessor processor). Thismethod sets the processor to process the template of this element. ThesetParent method may be declared as: public voidsetParent(java.lang.Object parent). This method sets the parent elementof this element. The setSibling method may be declared as: public voidsetSibling(XSTElement elem). This method sets the sibling element ofthis element.

The public interface of XSTtemplate further handles elements of the XSTprocessing language. This public interface includes several methods. ThegetParentTemplate method may be declared as: public XSTtemplategetParentTemplate( ). This method gets the parent template of thistemplate. The getID method may be declared as: public int getID( ). Thismethod gets the ID of this template. The getDOM method may be declaredas: public org.w3c.dom.Node getDOM( ). This method gets the DOM objectof this template. The getOccurrences method may be declared as: publicint getOccurrences( ). This method gets the number of usages of thistemplate. The getMaxOccurrences method may be declared as: public intgetMaxOccurrences( ). This method gets the allowed maximum number ofusages of this template. The isVariable method may be declared as:public boolean isVariable(java.lang.String name). This method checks ifthe template has a variable for the given name. It returns a flag toindicate if the template has a variable for the given name. ThesetParentTemplate method may be declared as: public voidsetParentTemplate(XSTtemplate templ). This method sets the parenttemplate of this template. The setVariable method may be declared as:public boolean setVariable(java.lang.String name, java.lang.Objectvalue). This method sets the content of a variable in this template. ThesetVariable method may be declared as: public booleansetVariable(java.lang.String name, java.lang.Object value, booleancheck). This method sets the content of a variable in this template. Inits parameter list: name is the name of the variable; value is thecontent of the variable to be set; and check is a flag to indicate thatthe content of the variable should be checked first. The write methodmay be declared as: public void write(java.io.OutputStream os) throwsjava.io.IO exception. This method writes the content of thetransformation of this template to the OutputStream.

The template used in the first embodiment efficiently transformsdocuments with simple rules. However, it relies on Schema AdjunctFramework to support logical operations and invoke Java extensionfunctions, which degrades performance and increases the complexity inthe template creation.

The second embodiment uses some of the familiar XSLT syntax in thetemplates. It builds the support of logical operations and Javaextensions into the template language. This feature enables XST toperform complex transformations. A template using the XSLT style syntaxof the second embodiment, is shown below.

<xst:template name=“Root” > <Root> Beginning of the template for Root<Boing><xst:var name=“Boing”/></Boing> <Node2><xst:varname=“Node2”/></Node2> End of the template for Root </Root></xst:template>In this sample, an attribute “name” is used to specify the name of thetemplate. Both “Boing” and “Node2” are local variables and their contentwill be sent to the transformed document automatically. A template canhave both global and local variables. The content of a local variablemay be sent to the output document automatically.

In the following template, “myVar” is a global variable. It can bereferenced in the following content of the template. Element “Node22” isa local variable. Its value is the content of the global variable“myVar”.

<xst:templates name=″SimpleTransform″xmlns:xst=″http://www.commerceone.com/XST″ version=″1.0″> <xst:templatename=″Root″ dom=″Root″ skip=″Node3|Node4″> <xst:var name=”myVar”select=”Node2”/> <Root> Beginning of the template for Root<Boing><xst:var name=″Boing″/></Boing> <Node2><xst:varname=″Node2″/></Node2> <Node22><xst:var name=″Node22″select=”$myVar”/></Node22> End of the template for Root </Root></xst:template> <xst:template name=″Node1″ dom=″Node1″> <Node1><xst:varname=″Node1″></Node1> </xst:template> </xst:templates>

A single template source is used for all the templates used in atransformation. A template source should start with the element<xst:templates>. The name of the source in the sample above is“SimpleTransform”. There are two templates, i.e. Root and Node1, in thesource above. Once loaded, all the templates in the template source willbe saved in memory for fast access. Interfaces will be provided to passin additional templates during a transformation.

A DOM can be created for a fragment or part of the source documentduring the streaming of the source by specifying the root node of theDOM in the attributes of a template. XPath expressions or treemanipulations can then be used to access the DOM.

<xst:template name=”OrderParty” domsrc=”OrderContact”dom=”OrderContact”> ...... <OrderContactName> <xst:varname=”ContactName” select=”//ContactName”/> </OrderContactName> ......</xst:template>In the above example, attribute “domsrc” defines the root node for theDOM source in the input document. This attribute will be used as thename of the created DOM for other templates to access it. Attribute“dom” specifies the name of the DOM to be used in this template. Oncecreated, a DOM is accessible to all templates used in a transformation.

The following is another template that reuses the DOM created by thetemplate in the previous example.

<xst:template name=”ShippingParty” dom=”OrderContact”> ......<OrderContactName> <xst:var name=”ContactName” select=”//ContactName”/></OrderContactName> ...... </xst:template>

Logical operations “if” and “choose” are supported in the secondembodiment.

<xst:if test=”ContactName”> <OrderContactName><xst:varname=”ContactName”/></OrderContactName> </xst:if>In this example, the test is on a leaf node “ContactName”. If a test isnot on a leaf node, a valid XPath expression must be used and thecontext nodes/DOM for the XPath should be available.

<xst:template name=”ShippingParty” dom=”OrderContact”> ...... <xst:iftest=”//OrderContact/Contact”> <OrderContactName>  <xst:varname=”ContactName” select=”//OrderContact/Contact/ContactName”/></OrderContactName> </xst:if> ...... </xst:template>Logical operation <choose> is also supported. Element <choose> has childelements <when> and <otherwise>.

<xsl:choose> <xsl:when test=″UOMCodedOther″> <UOMCoded><xst:var name=”UOMCodedOther “/></UOMCoded> </xsl:when> <xsl:otherwise><UOMCoded><xst:var name=” UOMCoded”/></UOMCoded> </xsl:otherwise></xsl:choose>Element <choose> can have multiple child elements <otherwise> to supportmultiple options.

<xsl:choose> <xsl:when test=″UOMCodedOther″> <UOMCoded><xst:var name=”UOMCodedOther “/></UOMCoded> </xsl:when> <xsl:otherwise test=” UOMCoded“> <UOMCoded><xst:var name=” UOMCoded”/></UOMCoded> </xsl:otherwise><xsl:otherwise> <UOMCoded>No UOMCoded Info</UOMCoded> </xsl:otherwise></xsl:choose>Only the last child element <otherwise> does not have the attribute“test”.

The following built-in functions are supported in the second embodiment.

A function string:

<xst:var name=”StreetAddress” select=”string(‘19191 Valco Parkway’)”/><xst:var name=”City” select=”string(‘Cupertino’)”/>A function concat:

<xst:var name=”Address” select=”concat($StreetAddress, ‘, ’)”/> <xst:varname=”Address” select=”concat($StreetAddress, $City)”/>A function string-length:

<xst:var name=“Length” select=“string-length($StreetAddress)”/>

A function sub-string:

<xst:var name=“StreetAddress” select=“sub-string($Address, 0, 19)”/>

In the above template, given the variable $Address=“19191 Valco Parkway,Cupertino”, the return from the function sub-string( . . . ) is “19191Valco Parkway” for the variable “StreetAddress”. Additional built-infunctions, that are supported by XSLT, such as addition (+), subtraction(−), multiplication (*), division (div), etc., may also be supported.

Java extension functions can be used just like the built-in functionswith the namespace/prefix “java”.

<xst:template name=”OrderInfo”xmlns:java=http://www.commerceone.com/xst/java> ...... <xst:varname=”OrderDate” select=”string(‘20011012T17:56:20’)”/> <xst:varname=”Date” select =”test.extensions.DateInfo:getXCBLDate($OrderDate)”/>...... </xst:template>The number of arguments used in the template to call a Java extensionfunction should match the number of arguments of that Java extensionfunction.

Different from XSLT, both global and local variables can be modifiedduring the transformation. The following is a sample of modifying globalvariables during the transformation.

<!-- Global variables using built-in functions --> <xst:var name=“gVar1”select=“string(‘This is a global variable’)”/> <xst:var name=“gVar2”select=“string-length(‘This is a global variable’)”/> <Root> Beginningof the template for Root <!-- Modify global variables --><ModifiedGlobalVariable> <xst:var name=“gVar1” select=“concat($gVar1,‘-modified’)”/> </ModifiedGlobalVariable> <ModifiedGlobalVariable><xst:var name=“gVar2” select=“number($gVar2+100.50)”/></ModifiedGlobalVariable> <!-- Modify again the global variable --><AgainModifiedGlobalVariable> <xst:var name=“gVar1”select=“concat($gVar1, ‘-again’)”/> </AgainModifiedGlobalVariable>

The schema for each of the XST elements can be found in FIG. 15A-C. InFIG. 15A-C, the value (required or optional) of attribute use for theattributes of an element can be determined.

The XML element templates is the root element of a template sourcedocument. It can have as its children comment, include, or template, asshown in the discussion above of variables, and as shown below.

<xst:templates name=”binding” xmlns:xst=“http://www.commerceone.com/XST”version=“1.0”> <xst:comment>This is a sample templates</xst:comment><!-First template --> <xst:template name=″Root″> <Root> <Boing><xst:bind-template name=″Node1″/> </Boing> <Node2><xst:var name=″Node2″select=”Node2”/><xst:val-of select=”$Node2”/></Node2> </Root></xst:template> <!-Second template --> <xst:template name=″Node1″><Node1><xst:val-of select=″param(Node1)″/></Node1> </xst:template></xst:templates>

In this sample, the element val-of is used for the content of <Node1>while elements var and val-of are used for that of element <Node2>.Those usages will be discussed below.

The element template provides the rules for a transformation within thescope/life-time of the template. It also provides the layout for thetarget/transformed document. A template is activated or loaded at theSAX event of startElement for the element it matches in the source XMLdocument and will be unloaded at the SAX event of endElement for thesame element. XST tries to send the transformed content of a template atthe event of endElement if possible. The syntax of the template elementis:

<xst:template  match=”element name to match”  namespace=”namespace tomatch”  copy=”true|false”  deferred=”true|false”  inclusive=”true|false” alias=”name only used when attribute copy is ture and inclusive isfalse”  domsrc=”name of the root element for the dom”  skip=”list ofelements to be skiped”  param=”list of elements to be saved” friend=”id(reserved for future use) ” >  ... </xst:template>

In this syntax, match is the ID/name of the element in the sourcedocument to match for which the template will be loaded/unloaded at theSAX event of startElement/endElement. Namespace is the namespace tomatch for the element. The default value is null. Copy is a flag tospecify whether the default behavior is to copy the source to the targetdocument. The default value is false. Deferred is a flag to specifywhether to defer the output of the content of the template until thecontent of its parent template is output. The default is false.Inclusive is a lag to specify whether to copy the name of the rootelement to the target document when copy=true. The default value istrue. Alias is a replacement for the name of the root element copied tothe target document when copy=true and inclusive=false. The defaultvalue is null. Domsrc is the name of the element in the source documentfor which a DOM is to be created within the scope of this template usingit as the root (element). DOM is always created as a global object andaccessible to all templates. The default value is null. Skip includes alist of names separated by “1” for the elements to be skipped during thetransformation. The default value is null. Param is a list of namesseparated by “1” for the elements to be saved for later use during thetransformation. The default value is null. Friend is an alias of thename of the element in the source document to match. The default valueis null.

Since the activation or loading and deactivation or unloading of atemplate are triggered by the SAX events, a parent template can be usedto defer the execution/output of its child templates to the time tooutput that of the parent. This is to insure that the needed informationis available before the execution of its child templates duringstreaming of the source document.

Again, the element val-of is used to send the selected content to thetarget document.

<xst:val-of  select=”select expression”  dom=”dom id” disable-output-escaping=”yes|false” </xst:value-of>Element val-of can be initialized using a valid XPath expression.

The following expressions can be used as the value of the attributeselect. Param refers to a parameter that is local to a template. Forexample: <xst:val-of select=“param(CountryCode)”/>. Variable is amutable variable. For example: <xst:val-of select=“$v”/>. Built-infunctions include those XST built-in functions described above. Forexample: <xst:val-of select=“string(‘my variable’)”/>. Java extension isa Java extension function. It must include the class path and methodname separated by “:” For example: <xst:val-ofselect=“com.commerceone.xst.test.InfoRetriver:getDateTime($v0, 2000)”/>.XPath/DOM is a valid Xpath expression with a DOM. For example:<xst:val-of select=“//ListOfItemDetail/ItemDetail”dom=“ListOfItemDetail”/>. The attribute dom is used to specify a DOMsource for the select/XPath expression.

Attribute disable-output-escaping is used to disable the escaping of thefollowing characters, <, > and &. The default is to escape thosecharacters as &lt; &gt; and &amp respectively.

The element var is used to define/declare a variable in XST. Variablesare mutable in XST. A variable can be either global or local to atemplate. All variables which are direct children of a template areglobal ones and accessible to all templates.

<xst:var  name=”id”  select=”select expression”  dom=”dom id” </xst:var>

Element var can be initialized using a valid XPath expression. Attributedom can be used to specify a DOM as the source for the select/XPathexpression. The same set of expressions as for element val-of can beused for element var.

The following code excerpt illustrates the expressions set out above.

<xst:templates name=”variables”xmlns:xst=“http://www.commerceone.com/XST” version=“1.0”> <xst:templatename=″Root″> <!-- Global variables using built-in functions --> <xst:varname=″gVar1″ select=″string(‘This is a global variable’)″/> <xst:varname=″gVar2″ select=″string-length(‘This is a global variable’)″/><Root> <!- Use global variables --> <UseGlobalVariable><xst:val-ofselect=″$gVar1″/></UseGlobalVariable> <UseGlobalVariable><xst:val-ofselect=″$gVar2″/></UseGlobalVariable> <!-- Modify global variables usingbuilt-in functions --> <ModifiedGlobalVariable> <xst:var name=″gVar1″select=″concat($gVar1, ‘-modified’)″/> <xst:val-of select=“$gVar1”/></ModifiedGlobalVariable> <ModifiedGlobalVariable> <xst:var name=″gVar2″select=″number($gVar2 + 100.50)″/> <xst:val-of select=”$gVar2”/></ModifiedGlobalVariable> <!-- Modify again global variables --><AgainModifiedGlobalVariable> <xst:var name=″gVar1″select=″concat($gVar1, ‘-again’)″/> <xst:val-of select=”$gVar1”/></AgainModifiedGlobalVariable> <ValOfNode2><xst:val-ofselect=″param(Node2)″/></ValOfNode2> <!-Use a param --><Node1><xst:val-of select=”param(Node1)”/></Node1> <Node2><xst:varname=″Node2″ select=”Node2”/><xst:val-of select=”$Node2”/></Node2><UseLocalVariable><xst:val-ofselect=“concat(‘**’,$Node2,‘**’)”/></UseLocalVariable> </Root></xst:template> </xst:templates>

In several examples that follow, the following XML source input is used:

<Root>  <Boing>  <Node1 bingo = “dingo”>This is Node 1</Node1>  </Boing> <Node2>This is Node 2</Node2> </Root>

This XML source input transformed using the preceding templates producesthe following output:

<Root> <UseGlobalVariable>This is a global variable</UseGlobalVariable><UseGlobalVariable>25</UseGlobalVariable> <ModifiedGlobalVariable>Thisis a global variable- modified</ModifiedGlobalVariable><ModifiedGlobalVariable>125.5</ModifiedGlobalVariable><AgainModifiedGlobalVariable>This is a global variable-modified-again</AgainModifiedGlobalVariable> <ValOfNode2>This is Node2</ValOfNode2> <Node1>This is Node 1</Node1> <Node2>This is Node2</Node2> <UseLocalVariable>**This is Node 2**</UseLocalVariable></Root>

The following is a sample template using a DOM attribute:

<xst:templates name=″doms-2″ xmlns:xst=″http://www.commerceone.com/XST″version=″1.0″> <xst:template name=″Root″> <!-Bind template Node1 for DOMcreation --> <xst:bind-template name=″Node1″/> <Root> <!-- DOM/XPath.The DOM is created in template Node1 --> <Node1><xst:val-ofselect=″//Node1[@bingo=‘dingo-1.1’]″ dom=”node1”/></Node1><Node1-attribute><xst:val-of select=″//@bingo″/ dom=”node1”></Node1-attribute> <Node1-attribute><xst:val-of select=″//@bingo=‘dingo-1’″dom=”node1”/></Node1-attribute> </Root> </xst:template> <!-Template usedonly to create the DOM --> <xst:template name=″Node1″ copy=”false”domsrc=″Node1″/> </xst:templates>

The DOM used in template Root above is created in the following templateNode1. The output document using this template and the source documentabove is:

<Root> <Node1>This is Node 1.1</Node1><Node1-attribute>dingo-1.1</Node1-attribute><Node1-attribute>false</Node1-attribute> </Root>

Element bind-template is used to activate or bind a template when thevalue of the template attribute match matches the name of an element inthe source document. This is only necessary when the template attributecopy is false. When copy is true, a template can bind/load any templateswithin its scope as long as the child template can match an element inthe source document. The syntax for matching and activating a templateis <xst:bind-template name=“id”/>.

The following template:

<xst:templates name=″bindings″xmlns:xst=″http://www.commerceone.com/XST″ version=″1.0″> <xst:templatematch=″Root″> Beginning of the template for Root <Root> <Boing> <!--Bind/load template Node1 --> <xst:bind-template name=″Node1″/> </Boing><Node2><xst:val-of select=″param(Node2)″/></Node2> </Root> End of thetemplate for Root </xst:template> <xst:template name=″Node1″> Beginningof the template for Node1 <xst:var name=″Node1″ select=”Node1”/><Node1><xst:val-of select=″$Node1″/></Node1> End of the template forNode1 </xst:template> </xst:templates>applied to the source input above, produces the following output:

Beginning of template for Root <Root> <Boing> Beginning of template forNode1 <Node1>This is Node 1</Node1>End of template for Node1 </Boing><Node2>This is Node 2</Node2> </Root> End of the template for Root

Element attribute is used to add/append an attribute to a user definedelement. Its syntax is:

<xst:attribute  name=”id”  select=”select expression” </xst:attribute>

Like elements val-of and var, the select expression is a valid XPathexpression.

The following templates:

<xst:templates name=“attributes”xmlns:xst=“http://www.commerceone.com/XST” version=“1.0”> <xst:templatename=“Root”> <xst:var name=“Node2” select=”Node2”/> <Root> <Node2> <!--Attribute using a variable --> <xst:attribute name=“attr1”select=“$Node2”/> <!-- Attribute using a built-in function --><xst:attribute name=“attr2” select=“string(‘my attribute 2’)”/> <!--Attribute using a param --> <xst:attribute name=“attr3”select=“param(Node2)”/> <xst:val-of select=“param(Node2)”/> </Node2></Root> </xst:template> </xst:templates>when applied to the source input above, produces the following output:

<Root> <Node2 attr1=“This is Node 2” attr2=“my attribute 2” attr3=“Thisis Node 2”> This is Node 2 </Node2> </Root>

Elements if, choose, when and otherwise are used to provide logicaloperations in XST. A valid XPath expression can be used for the “testexpression”, i.e. the value of the attribute test. Their syntax is:

<xst:if test=”test expression”> ... </xst:if> ... ... <xst:choose> <xst:when test=”test expression”>  ...  </xst:when>  <xst:otherwisetest=”test expression”>  ...  </xst:otherwise>  <xst:otherwisetest=”test expression”>  ...  </xst:otherwise>  ...  <!-The lastotherwise in the logical construct should not have a test expression--> <xst:otherwise>  ...  </xst:otherwise> </xst:choose>

The following template:

<xst:templates name=″logical-operators″xmlns:xst=″http://www.commerceone.com/XST″ version=″1.0″> <xst:templatename=″Root″> <Root> <xst:var name=″Node2″ select=”Node2”/><Node2><xst:val-of select=”$Node2”/></Node2> <xst:if test=″$Node2=‘Thisis Node 2’″>  <ResultOfLogicalOperations>Node2=″This is Node2″</ResultOfLogicalOperations> </xst:if> <xst:if test=″$Node2″> <ResultOfLogicalOperations>Has a variable -$Node2</ResultOfLogicalOperations> </xst:if> <xst:if test=″not($Node2)″> <ResultOfLogicalOperations>Does not has a variable -$Node2</ResultOfLogicalOperations> </xst:if> <xst:choose>  <xst:whentest=″$Node2=‘This is Node 1’″> <Out>This is Node 1</Out>  </xst:when> <xst:otherwise test=″$Node2=‘This is Node 2’″> <Out>This is Node2</Out>  </xst:otherwise>  <xst:otherwise test=″$Node2=‘This is Node3’″> <Out>This is Node 3</Out>  </xst:otherwise>  <xst:otherwise><Out>This is Node x</Out>  </xst:otherwise> </xst:choose> </Root></xst:template> </xst:templates>applied to the source input above, produces the following output:

<Root> <Node2>This is Node 2</Node2><ResultOfLogicalOperations>Node2=“This is Node2”</ResultOfLogicalOperations> <ResultOfLogicalOperations>Has avariable - $Node2</ResultOfLogicalOperations> <Out>This is Node 2</Out></Root>

Element comment is used to add comments to the target document. It canbe the child of any template elements. Its syntax is:

<xst:comment>  content of the comments </xst:comment>

Element fall-back is used to provide the opportunity for an applicationto handle the error events or the debug information when an action failsfor the template elements bind-template, load-template, and redirect.

The following template illustrates the syntax of fall-back.

<xst:template ...> ... <xst:load-template name=”$templateName”> <xst:fall-back>  <xst:message>Fail to load template <xst:value-ofselect=”$templateName”/></xst:message>  </xst fall-back> ...</xst:template>If the specified template can't be loaded, the message will be sent toeither the ErrorHandler provided by the application or to the targetdocument.

Element for-each is used to loop through a set of nodes in a DOM orother tree structure created for a fragment or subsection of the inputdocument. Its syntax is:

<xst:for-each select=”select expression” dom=”id”>  .... </xst:for-each>

The following template:

<xst:templates name=″for-each″xmlns:xst=″http://www.w3.org/1999/XSL/Transform″ version=″1.0″><xst:template name=″OrderDetail″ domsrc=″ListOfItemDetail″><OrderDetail> <xst:for-each select=″//ListOfItemDetail/ItemDetail″dom=”ListOfItemDetail”>  <BuyerLineItemNum><xst:val-ofselect=″local-name( )″/>-<xst:val-of select=″.″/></BuyerLineItemNum></xst:for-each> </OrderDetail> </xst:template> </xst:templates>when applied to the following source input:

<Order> <OrderDetail> <ListOfItemDetail> <ItemDetail><BuyerLineItemNum>8001</BuyerLineItemNum> </ItemDetail> <ItemDetail><BuyerLineItemNum>8002</BuyerLineItemNum> </ItemDetail></ListOfItemDetail> </OrderDetail> </Order>produces the following output:

<OrderDetail> <BuyerLineItemNum>ItemDetail-8001</BuyerLineItemNum><BuyerLineItemNum>ItemDetail-8002</BuyerLineItemNum> </OrderDetail>

Element include is used to include additional templates stored in atemplate source. A URIResolver provided by the application is used toresolve the uri for the included source. Its syntax is, <xst:includehref=“uri”/>.

Element load-template is used to activate or load a template, in memory,dynamically as the content of the template under execution is beingoutput. The loading template can pass parameters to the template loaded.Those parameters need not be declared in the template loaded. The loadedtemplate can access the runtime context of the loading template whichincludes the local variables and params. Its syntax is:

<xst:load-template name=”template id”>  <xst:with-parm name=”id1”select=”select expression/>  <xst:with-parm name=”id2” select=”selectexpression/>  ... </xst:load>The following sample “templates” includes a pair of “template” elements,according to the second embodiment:

<xst:templates name=″loading″ xmlns:xst=″http://www.commerceone.com/XST″ version=″1.0”> <xst:template name=″Root″><xst:var name=″Node1″ select=”Node1”/> <Root> <Node1> <xst:load-templatename=″loaded″/> <xst:with-param name=″message″ select=″string(‘This isthe output from a loaded tempate: Node1 is not null.’)″/> </Node1></Root> </xst:template> <xst:template name=″loaded″> <xst:iftest=″$Node1″> <xst:value-of select=″$message″/> </xst:if></xst:templates>In the above sample, template “loaded” is loaded by template “root”. Theequivalent template after the loading is shown below.

<xst:templates name=″loading″ xmlns:xst=″http://www.commerceone.com/XST″ version=″1.0″> <xst:template name=″Root″><xst:var name=″Node1″ select=”Node1”/> <Root> <Node1> <xst:iftest=″$Node1″> <xst:value-of select=″string(‘This is the output from aloaded template: Node1 is not null.’)″/> </xst:if> </Root></xst:template> </xst:templates>

Element message is used to for customized messages. Its syntax is,<xstmessage> content of the message</xstmessage>

Element redirect is used to redirect a part of the output to a specifiedtarget. Its syntax is:

<xst:redirect eref=“id”> <!-Content to be redirected --> </xst:redirect>The following is a sample templates using redirect:

<xst:templates name=″redirect″xmlns:xst=″http://www.w3.org/1999/XSL/Transform″ version=″1.0″><xst:template name=″ChangeOrderHeader″> ... <xst:redirecteref=”http://www.commerceone.com/sql/db_id”> <ChangeType> <ChangeTypeCoded><xst:val-ofselect=param(AddAdditionalItems)”/></ChangeTypeCoded> </ChangeType></xst:redirect> ... </xst:template> </xst:templates>A valid XPath expression can be used for the value of the attributeeref.

<xst:templates name=″redirect″xmlns:xst=″http://www.w3.org/1999/XSL/Transform″ version=″1.0″><xst:template name=″ChangeOrderHeader″> <xst:var name=”db_id”select=”param(refNum)”/> ... <xst:redirecteref=”concat(string(‘http://www.commerceone.com/sql/ db_id’), $db_id)”><ChangeType>  <ChangeTypeCoded><xst:val-ofselect=param(AddAdditionalItems)”/></ChangeTypeCoded> </ChangeType></xst:redirect> ... </xst:template> </xst:templates>The entity reference eref should be resolved by the URIResolver providedby the application and the return should be an object ofcom.commerceone.xst.swi.jaxp.ResultManager which can manage/close theopened Result object for the “redirect”.

In some embodiments, both streaming and buffered modes of transformationare supported. In a streaming mode transformation, the root template isin copy-mode. XST streams out small buffers of transformed content asdata for output becomes available. Before loading or activating a childtemplate, the parent template streams out the transformed content ofitself to clear the path for the streaming of its child templates.Before unloading or deactivating a template, the template streams outthe transformed content of itself to clear the path for the streaming ofits siblings. In a buffered mode transformation, the root template isnot in copy-mode. XST does not stream out the transformed content. Itappends the transformed content of a template, before unloading it, toits parent if the parent is in a copy-mode.

A deferred-mode template is used when the needed information for atransformation is not available for the time being. It providesbuffering for less than a whole transformation. Deferred-mode suspendsthe default behavior of streaming during processing of a template. Adeferred-mode template registers with its parent template instead ofstreaming out its content. Deferred-mode has no effect in a bufferedtransformation since the entire transformation is, in effect, deferred.One embodiment of template rules allows a template to have only oneregistered child template to be deferred. Other embodiments may supportan arbitrary number of registered child templates to be deferred. In theone embodiment, a parent template streams out any transformed content ofa previously registered child template, if there is one, and its owncontent before it registers a new child template.

In the first embodiment, streaming on demand can be implemented withdummy templates. Streaming of the transformed content of a template isdone at the SAX event of either startElement or endElement. By addingdummy templates, we can introduce additional SAX events to reduce thetransformed content in memory which will result in increased speed oftransformation.

While the present invention is disclosed by reference to the preferredembodiments and examples detailed above, it is understood that theseexamples are intended in an illustrative rather than in a limitingsense. Computer-assisted processing is implicated in the describedembodiments. Accordingly, the present invention may be embodied inmethods for computer-assisted processing, systems including logic tocarry out transform processing, media impressed with logic to carry outtransform processing, data streams impressed with logic to carry outtransform processing, or computer-accessible transform processingservices. It is contemplated that modifications and combinations willreadily occur to those skilled in the art, which modifications andcombinations will be within the spirit of the invention and the scope ofthe following claims.

We claim as follows:
 1. A computer-implemented method of transforming adocument, including: using a processor, responding to an elementstart-event in an event data stream by searching for a named templatethat matches the element start-event, upon finding a matching namedtemplate, activating the named template, and upon not finding thematching named template, treating an element between the elementstart-event and an element end-event of the event data stream as contentof a parent element; and responding to the element end-event paired tothe element start-event, using the activated named template, including:responsive to instructions in the named template, outputting at leastinformation from or corresponding to (i) the named template, (ii) anelement or (iii) other processing related to the named template.
 2. Themethod of claim 1, wherein the event data stream represents anelectronic commerce document.
 3. The method of claim 1, wherein theevent data stream represents a document including character dataencoding text characters and markup data identifying sets of storageunits according to a logical structure of the document.
 4. The method ofclaim 3, wherein a plurality of named templates is stored in a templatessource.
 5. The method of claim 1, wherein the responding to the elementstart-event further includes activating one or more variables with avariable scope corresponding to the named template, and wherein theresponding to the element end-event paired to the element start-eventfurther includes deactivating the variables.
 6. The method of claim 5,wherein the responding to the element end-event corresponding to thenamed template further includes processing logic instructions tomanipulate the variables.
 7. The method of claim 1, wherein theresponding to the element start-event further includes, in response toan instruction associated with the named template, creating a treerepresentation limited to the element and sub-elements within a scope ofthe named template.
 8. The method of claim 1, further includingreceiving, in the event data stream, one or more mutable variables thatcan be changed using logical, string or arithmetic operations.
 9. Themethod of claim 1, wherein the information from or corresponding to (i)the named template, (ii) the element or (iii) other processing relatedto the named template includes some of literal text, input eventsreceived in the event data stream between the element start-event andthe element end-event, or variables that store values from content,attributes or labels of the element.
 10. A computer-implemented methodof transforming a document, including: using a processor, responding toan element start-event in an event data stream by searching for a firstnamed template that matches the element start-event, upon finding amatching first named template, activating the first named template, andupon not finding the matching first named template treating an elementbetween the element start-event and an element end-event as content of aparent element; responding to a nested element start-event in the eventdata stream by matching the nested element start-event to a second namedtemplate and activating the second named template; responding toadditional events in the event data stream according to instructions ina most recently activated named template; and responding to the elementend-event paired to the nested element start-event by processing thesecond named template, including: responsive to instructions in thesecond named template, outputting at least information from orcorresponding to (i) the second named template, (ii) an element or (iii)other processing related to the second named template.
 11. The method ofclaim 10, wherein the responding to the nested element start-eventfurther includes activating variables in a scope of the second namedtemplate, and wherein the instructions in a recent second named templateinclude assigning input to one or more of the variables.
 12. The methodof claim 10, wherein events in the event data stream correspond to anelectronic commerce document including character data encoding textcharacters and markup data identifying sets of storage units accordingto a logical structure of the electronic commerce document.
 13. Themethod of claim 12, wherein a plurality of named templates is storedtogether in a templates source.
 14. The method of claim 10, wherein theresponding to the nested element start-event further includes, inresponse to an instruction associated with the second named template,creating a tree representation limited to the element and sub-elementswithin a scope of the second named template.
 15. The method of claim 10,further including receiving, in the event data stream, one or moremutable variables that can be changed using logical, string orarithmetic operations.
 16. A non-transitory computer memory media,including computer program instructions that direct a processor to:respond to an element start-event in an event data stream by searchingfor a named template that matches the element start-event, upon findinga matching named template, activating the named template, and upon notfinding the matching named template, treating an element between theelement start-event and an element end-event of the event data stream ascontent of a parent element; and respond to the element end-event pairedto the element start-event, using the activated named template, by:responsive to instructions in the named template, outputting at leastinformation from or corresponding to (i) the named template, (ii) anelement or (iii) other processing related to the named template.
 17. Thenon-transitory computer memory media of claim 16, further includinginstructions that direct a processor to: respond to the elementstart-event further by activating one or more variables with a variablescope corresponding to the named template; and respond to the elementend-event paired to the element start-event further by deactivating thevariables.
 18. The non-transitory computer memory media of claim 16,further including computer program instructions that direct theprocessor to receive, in the event data stream, one or more mutablevariables that can be changed using logical, string or arithmeticoperations.
 19. A non-transitory computer memory media, includingcomputer program instructions that direct a processor to: load into amemory one or more templates; and process an event data stream,including repeatedly: searching for a named template that matches anelement start-event in the event data stream, upon finding a matchingnamed template, activating the named template, and upon not finding thematching named template, treating an element between the elementstart-event and an element end-event of the event data stream as contentof a parent element; and processing instructions in the matching namedtemplate to transform a buffered input stream that is buffered until theelement end-event, and to output results of the transform of thebuffered input stream.
 20. The non-transitory computer memory media ofclaim 19, further including instructions that direct a processor to:activate one or more variables in a scope of the named template, uponthe finding of the matching named template; and deactivate the variablesin the scope of the named template, upon release for reuse of thememory.
 21. The non-transitory computer memory media of claim 19,further including computer program instructions that direct theprocessor to receive, in the event data stream, one or more mutablevariables that can be changed using logical, string or arithmeticoperations.